//过滤图片
const imgDate = (img) => {
	var imgDate = 'http://zhiapi.2pe.cn' + img
	return imgDate
}
const formatDate = (time) => {
	if (!time) { //当时间是null或者无效格式时返回空
		return 'Không'
	} else {
		var date = new Date(time * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
		var month = date.getMonth() + 1;
		if (month < 10)
			month = "0" + month;
		var hours = date.getHours();
		if (hours < 10)
			hours = "0" + hours;
		var minutes = date.getMinutes();
		if (minutes < 10)
			minutes = "0" + minutes;
		var seconds = date.getSeconds();
		if (seconds < 10)
			seconds = "0" + seconds;
		var time = date.getFullYear() + "-" + month + "-" + date.getDate() +
			"  " + hours + ":" + minutes + ":" + seconds;
		return time;


	}
}
//过滤金额
const moneyDate = (money) => {
	if (!money) {
		return '0.00'
	} else {
		var mon = parseFloat(money)
		if (mon >= 10000) {
			var price = parseFloat(mon / 10000).toFixed(2);
			return price + '万';
		} else {
			return money;
		}




	}
}


//过滤金额
const moneyceshi = (money) => {
	money = (parseFloat(money) * 100).toFixed(2)

	return money
}
//过滤金额
const toFixed0 = (money) => {
	money = parseFloat(money).toFixed(0)
	return money
}

//默认头像
const moimg = (img) => {
	if (img == undefined || img == 'undefined' || img == '') {
		img = '../../static/moren.png'
	}
	return img
}
//默认背景
const bgimg = (img) => {
	if (img == undefined || img == 'undefined' || img == '') {
		img = '../../static/morenbg.png'
	}
	return img
}

//
const guolv_time = (time) => {
	var date = new Date();
	var jintian = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate()
	if(time == jintian){
		return "今天"
	}
	var date = new Date();
	date.setDate(date.getDate()-1)
	var zuotian = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate()
	if(time == zuotian){
		return "昨天"
	}
	return time
}
const jisuan = (time) => {
	var date = new Date();
	var jintian = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate()
	var day1 = new Date(jintian);
	var day2 = new Date(time);

	return (day2 - day1) / (1000 * 60 * 60 * 24) +'天'
}

const fengetime = (time) => {
	if(time){
		var shijian = time.split(" ")
		return shijian[0]
	}else{
		return time
	}
	

	
}
export {
	formatDate,
	moneyDate,
	moneyceshi,
	imgDate,
	toFixed0,
	moimg,
	bgimg,
	guolv_time,
	jisuan,
	fengetime
}
